package com.study.mapper;

import com.github.pagehelper.Page;
import com.study.dto.ActivityCollectionListPageQueryDTO;
import com.study.dto.ActivitySearchDTO;
import com.study.entity.Activity;
import com.study.entity.ActivityCollection;
import com.study.vo.ActivityVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ActivityMapper {
    /**
     * 根据状态数组获取活动列表
     *
     * @param activitySearchDTO
     * @return
     */
    List<ActivityVO> getList(ActivitySearchDTO activitySearchDTO);

    /**
     * 根据用户id获取收藏的活动列表
     *
     * @param userId
     * @return
     */
    Page<ActivityVO> getCollectionActivityListByUserId(ActivityCollectionListPageQueryDTO userId);

    /**
     * 根据活动id获取活动详情
     * @param activityId
     * @return
     */
    @Select("select * from activities where id = #{activityId}")
    Activity getActivityById(Long activityId);

    /**
     * 根据用户id和活动id获取活动详情
     * @param userId
     * @param activityId
     * @return
     */
    @Select("select * from collection_activity where user_id = #{userId} and activity_id = #{activityId}")
    ActivityCollection getActivityByUserIdAndActivityId(Long userId, Long activityId);

    /**
     * 添加收藏
     * @param userId
     * @param activityId
     * @param creatTime
     */
    @Insert("insert into collection_activity(user_id, activity_id, create_time) " +
            "values(#{userId}, #{activityId}, #{creatTime})")
    void collectionActivity(Long userId, Long activityId, LocalDateTime creatTime);

    /**
     * 取消收藏
     * @param id
     */
    @Delete("delete from collection_activity where id=#{id};")
    void cancelCollectionActivity(Long id);

    /**
     * 根据活动id获取活动名称
     * @param id
     * @return
     */

    @Select("select activity_name from activities where id = #{id}")
    String getActivityNameById(Long id);
}
